//
//  DestTravePhotoesCollectionViewCell.m
//  TravelEveryDay
//
//  Created by dlios on 15/10/29.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "DestTravePhotoesCollectionViewCell.h"
#import "BaseHeader.h"
@implementation DestTravePhotoesCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.MainImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        self.MainImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer  *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ImageViewTap)];
        [self.MainImageView addGestureRecognizer:tap];
        self.baseScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        self.baseScrollView.contentSize = CGSizeMake(frame.size.width , frame.size.height);
        _baseScrollView.delegate = self;
        _baseScrollView.maximumZoomScale = 2;
        _baseScrollView.minimumZoomScale = 0.5;
        [self.contentView addSubview:_baseScrollView];
        [self.baseScrollView addSubview:_MainImageView];
    }
    return self;
}
- (void)ImageViewTap {
    [self.imageDelegate imageTap];
}
- (void)setDataModel:(DestTravePhotoesModel *)dataModel{
    NSMutableDictionary *dic= dataModel.photo_info;
    NSNumber *h = [dic objectForKey:@"h"];
    NSNumber *w = [dic objectForKey:@"w"];
    if (dic == nil) {
        self.MainImageView.frame  =CGRectMake(0, 0, SCREEN_WIDTH, 500);
    }else{
       self.MainImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * h.floatValue / w.floatValue);
    }
    self.MainImageView.center = self.contentView.center;
    NSURL *url = [NSURL URLWithString:dataModel.photo_1600];
    [self.MainImageView sd_setImageWithURL:url placeholderImage:PLACEHOLDERIMAGE];

//    _dayLabel.text = [NSString stringWithFormat:@"第%@天",dataModel.day ];
//    _dayLabel.textAlignment = NSTextAlignmentCenter;
//    _textLabel.text = dataModel.text;
//    _cityLabel.text = dataModel.city;
//    _timeLabel.text = dataModel.local_time;
    
    
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    CGFloat offsetX = (scrollView.bounds.size.width > scrollView.contentSize.width)?
    (scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5 : 0.0;
    CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?
    (scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5 : 0.0;
    _MainImageView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX,
                                 scrollView.contentSize.height * 0.5 + offsetY);
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _MainImageView;
}

@end
